package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {
    //交换机fanoutExchange
    //获得的消息会向与他绑定的队列各发一份
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("itcast.fanout");
    }

    //声明队列fanoutQueue1
    @Bean
    public Queue fanoutQueue1() {
        return new Queue("fanout.queue1");
    }

    //将队列fanoutQueue1绑定到交换机fanoutExchange
    @Bean
    public Binding fanoutBinding1(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    //声明队列fanoutQueue2
    @Bean
    public Queue fanoutQueue2() {
        return new Queue("fanout.queue2");
    }

    //将队列fanoutQueue2绑定到交换机fanoutExchange
    @Bean
    public Binding fanoutBinding2(Queue fanoutQueue2, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    //交换机directExchange
    //根据消息的rountingKey和队列的key进行匹配，相同则发送
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("itcast.direct");
    }

    //交换机topicExchange
    //根据通配符发送消息
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("itcast.topic");
    }

    @Bean
    public Queue objectQueue() {
        return new Queue("object.queue");
    }
}
